/////////////////////////////////////////////////////////////////////////////
// Name:        batchencoder.h
// Purpose:     A class to convert a number of text files to WAV and then to
//              MP3.
// Author:      Julian Smart
// Modified by: 
// Created:     2009-02-10
// RCS-ID:      
// Copyright:   (c) Julian Smart
// Licence:     New BSD License
/////////////////////////////////////////////////////////////////////////////

#ifndef _BATCHENCODER_H_
#define _BATCHENCODER_H_

/*
 * Includes
 */

#include "tts/tts.h"
#include "tts/mp3encoder.h"

/*
 * Styles and types
 */

typedef enum {
    wxBATCHMP3ENCODER_STATUS_IDLE,
    wxBATCHMP3ENCODER_STATUS_STARTING,
    wxBATCHMP3ENCODER_STATUS_TTS,
    wxBATCHMP3ENCODER_STATUS_ENCODING_MP3
} wxBatchTextToMP3EncoderStatus;

#define wxBATCHMP3ENCODER_OPTION_ENCODE_MP3             1

#define wxBATCHMP3ENCODER_VERBOSITY_ERRORS              0
#define wxBATCHMP3ENCODER_VERBOSITY_ERRORS_AND_WARNINGS 1
#define wxBATCHMP3ENCODER_VERBOSITY_VERBOSE             2

/**
    @class wxBatchTextToMP3Encoder
    
    A class for doing text to MP3 encoding in the background.

    @category{tts}
 */

class wxBatchTextToMP3EncoderProcess;

class wxBatchTextToMP3Encoder: public wxEvtHandler
{    
    DECLARE_DYNAMIC_CLASS( wxBatchTextToMP3Encoder )

public:
// Constructors

    wxBatchTextToMP3Encoder();
    ~wxBatchTextToMP3Encoder();

// Operations

    /// Member initialisation
    void Init();

    /// Set data
    virtual bool SetData(const wxArrayString& textFilenames, const wxArrayString& audioFilenames, const wxID3InfoArray& infoArray);

    /// Starting encoding the text files to MP3
    virtual bool Start(int options = 0, wxString* log = NULL);

    /// Check whether the next step should be done.
    /// If it returns false, the whole batch process has finished.
    /// finished can be set to true if the whole process has _just_ finished.
    virtual bool Process(wxString* log = NULL, bool* finished = NULL);

    /// Is it busy?
    virtual bool IsBusy() { return (m_textToSpeech.IsSpeaking() || m_mp3Encoder.IsEncoding() || m_status != wxBATCHMP3ENCODER_STATUS_IDLE); }

    /// Stop encoding
    virtual bool Stop();

    /// Set/get the options
    void SetOptions(int options) { m_options = options; }
    int GetOptions() const { return m_options; }

    /// Set/get the Espeak options
    //void SetEspeakOptions(int options) { m_espeakOptions = options; }
    //int GetEspeakOptions() const { return m_espeakOptions; }

    /// Set/get the MP3 encoder options
    void SetMP3EncoderOptions(int options) { m_mp3EncoderOptions = options; }
    int GetMP3EncoderOptions() const { return m_mp3EncoderOptions; }

    /// Get the wxEspeak object
    wxTextToSpeech& GetSpeech() { return m_textToSpeech; }
    const wxTextToSpeech& GetSpeech() const { return m_textToSpeech; }

    /// Get the wxMP3Encoder object
    wxMP3Encoder& GetMP3Encoder() { return m_mp3Encoder; }
    const wxMP3Encoder& GetMP3Encoder() const { return m_mp3Encoder; }

    /// Set/get the current file
    void SetCurrentFile(int currentFile) { m_currentFile = currentFile; }
    int GetCurrentFile() const { return m_currentFile; }

    /// Set/get the current status
    void SetStatus(wxBatchTextToMP3EncoderStatus status) { m_status = status; }
    wxBatchTextToMP3EncoderStatus GetStatus() const { return m_status; }

    /// Set/get the frame whose status line should be used for information
    void SetFrame(wxFrame* frame, int statusField = 0) { m_frame = frame; m_statusField = statusField; }
    wxFrame* GetFrame() const { return m_frame; }

    /// Set/get the verbosity
    void SetVerbosity(int verbosity) { m_verbosity = verbosity; }
    int GetVerbosity() const { return m_verbosity; }

    const wxArrayString& GetTextFilenames() const { return m_textFilenames; }
    const wxArrayString& GetOutputFilenames() const { return m_outputFilenames; }
    const wxID3InfoArray& GetID3InfoArray() const { return m_infoArray; }

protected:
    int                 m_options;          // remember the options
    //int                 m_espeakOptions;
    int                 m_mp3EncoderOptions;

    wxTextToSpeech      m_textToSpeech;
    wxMP3Encoder        m_mp3Encoder;

    wxArrayString       m_textFilenames;
    wxArrayString       m_outputFilenames;
    wxID3InfoArray      m_infoArray;

    int                 m_currentFile;
    wxBatchTextToMP3EncoderStatus   m_status;

    wxFrame*            m_frame;
    int                 m_statusField;
    int                 m_verbosity; // 0 - errors only, 1 - errors and warnings, 2 - verbose
};

#endif
    // _BATCHENCODER_H_

